//
//  ZLFunctionMacro.h
//
//  Created by Jiaozl on 2018/10/23.
//

#ifndef ZLFunctionMacro_h
#define ZLFunctionMacro_h

#endif /* ZLFunctionMacro_h */


#define iOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define iOS10 ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0)

#define mAppDelegate        (AppDelegate *)[[UIApplication sharedApplication] delegate]
#define mWindow             [[[UIApplication sharedApplication] windows] firstObject]
#define mKeyWindow          [[[UIApplication sharedApplication] delegate] window]
#define mUserDefaults       [NSUserDefaults standardUserDefaults]
#define mNotificationCenter [NSNotificationCenter defaultCenter]
#define mApplication        [UIApplication sharedApplication]

#define mIphoneStoryBoard   [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]

#define NUM2STR_GT0(obj) ([obj integerValue] != 0 ? [NSString stringWithFormat:@"%@", obj] : @"")
#define NIL_STRING(str) str.length > 0 ? str : @""
#define NIL_RETURN(CONTENT, MESSAGE) \
if (!CONTENT || !CONTENT.length) { \
[MBProgressHUD showError:MESSAGE];                                    \
return;                                                               \
}
#define NIL_RETURN_NO(CONTENT, MESSAGE) \
if (!([NIL_STRING(CONTENT) clearAllSpace]) || !([NIL_STRING(CONTENT) clearAllSpace]).length) { \
[MBProgressHUD showError:[NIL_STRING(MESSAGE) clearAllSpace]];                                    \
return NO;                                                               \
}

//加载图片
#define mImageByName(name)        [UIImage imageNamed:name]
#define mImageByPath(name, ext)   [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:name ofType:ext]]

//以tag读取View
#define mViewByTag(parentView, tag, Class)  (Class *)[parentView viewWithTag:tag]
//读取Xib文件的类
#define mViewByNib(Class, owner) [[[NSBundle mainBundle] loadNibNamed:Class owner:owner options:nil] lastObject]

//id对象与NSData之间转换
#define mObjectToData(object)   [NSKeyedArchiver archivedDataWithRootObject:object]
#define mDataToObject(data)     [NSKeyedUnarchiver unarchiveObjectWithData:data]

//度弧度转换
#define mDegreesToRadian(x)      (M_PI * (x) / 180.0)
#define mRadianToDegrees(radian) (radian*180.0) / (M_PI)

//颜色转换
#define mRGBColor(r, g, b)   [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
#define mRGBAColor(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
//rgb颜色转换（16进制->10进制）
#define mRGBToColor(rgb) [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:1.0]

#define kShowHUD [MBProgressHUD showLoading]


#define kHiddenHUD [MBProgressHUD hideHUD]

//G－C－D
#define kGCDBackground(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define kGCDMain(block)       dispatch_async(dispatch_get_main_queue(),block)

//判断是否为 iPhoneXS  Max，iPhoneXS，iPhoneXR，iPhoneX 系列
#define KIsiPhoneX (((int)((mScreenHeight/mScreenWidth)*100) == 216) ? YES : NO)

//----------页面设计相关-------

#define mScreenWidth          ([UIScreen mainScreen].bounds.size.width)
#define mScreenHeight         ([UIScreen mainScreen].bounds.size.height)
#define mScreenBounds         ([UIScreen mainScreen].bounds)

#define mNavBarFullHeight       ([UIDevice zl_navigationFullHeight])
#define mTabbarFullheight       ([UIDevice zl_tabBarFullHeight])
#define mStatusBarHeight        ([UIDevice zl_statusBarHeight])
#define mNavBarHeight           ([UIDevice zl_navigationBarHeight])
#define mTabbarHeight           ([UIDevice zl_tabBarHeight])

//----------设备系统相关---------

#define mIsPad    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define mIsiphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define mSystemVersion   ([[UIDevice currentDevice] systemVersion])
#define mCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//市场版本号
#define VERSION (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
//构建build的版本号
#define SUB_VERSION (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

#define DocumentPath  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

#define HasLogin [[AccountManager sharedAccountManager] hadLogin]

// weak strong dance
#define weakify(var) __weak typeof(var) XYWeak_##var = var;
#define strongify(var) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
__strong typeof(var) var = XYWeak_##var; \
_Pragma("clang diagnostic pop")
